package com.yaoxuguang.concurrence.threadBase.NotShareDataDemo;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.threadBase.NotShareDataDemo
 * @Description: 测试多线程的不可见
 * @date 2018年12月17日14:15
 */
public class Test {
    public static void main(String[] args) {
       /* MyThread myThreada = new MyThread("A");
        MyThread myThreadb = new MyThread("B");
        MyThread myThreadc = new MyThread("C");
        myThreada.start();
        myThreadb.start();
        myThreadc.start();*/

       /**
        *由c计算,count=3
        *由a计算,count=2
        *由b计算,count=3
        *由d计算,count=1
        *由e计算,count=0
        *产生了非线程安全的问题
        * 解决方案：给需要运行的方法加synchronized
        */
       MyThread myThread = new MyThread();
       Thread a = new Thread(myThread,"a");
       Thread b = new Thread(myThread,"b");
       Thread c = new Thread(myThread,"c");
       Thread d = new Thread(myThread,"d");
       Thread e = new Thread(myThread,"e");
        a.start();
        b.start();
        c.start();
        d.start();
        e.start();
    }
}
